package mainClient;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;

import CorbaModule.ICorbaServer;
import CorbaModule.ICorbaServerHelper;

public class CorbaClient extends DefaultClient
{
  private String m_ip;
  private int m_port;  
  private boolean m_isConnected = false;
  private ICorbaServer m_corba;

  public CorbaClient(int port, String ip, int selfPort)
  {
    m_port = port;
    m_ip = ip;
  }
  
  @Override
  public boolean connect()
  {
	String[] args = new String[4];
		
	args[0] = "-ORBInitialPort";
	args[1] = "1050";
	args[2] = "-ORBInitialHost";
	args[3] = "127.0.0.1";
		
	try 
	{
		ORB orb = ORB.init(args, null);
		org.omg.CORBA.Object namingContextObj = orb.resolve_initial_references("NameService");
		NamingContext namingContext = NamingContextHelper.narrow(namingContextObj);
			
		NameComponent[] path = {new NameComponent("JetGame", "Object") };
		org.omg.CORBA.Object remoteGameObj = namingContext.resolve(path);
		m_corba = ICorbaServerHelper.narrow(remoteGameObj);
		m_id = m_corba.connect();
	} 
	catch (Exception e) 
	{
		e.printStackTrace();
		return false;
	}	
		
	return true;
  }

  @Override
  public boolean disconnect()
  {
    m_corba.disconnect(m_id);
    return true;
  }

@Override
public String SendBDR() {
	return null;
	// TODO Auto-generated method stub
	
}
  
  
   
}
